package com.ostrich.cloud.ostrichGoodsService.service.component;

import cn.hutool.json.JSONUtil;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.GrounpByDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

public class ServerEncoder implements Encoder.Text<GrounpByDto> {
    private static final Logger log = LoggerFactory.getLogger(ServerEncoder.class);

    /**
     * 这里的参数 hashMap 要和  Encoder.Text<T>保持一致
     * @param hashMap
     * @return
     * @throws EncodeException
     */
    @Override
    public String encode(GrounpByDto hashMap) throws EncodeException {

        try {
            String s = JSONUtil.toJsonStr(hashMap);
            log.info(s);
            return s;
        }catch (Exception e){
            log.error("",e);
        }
        return null;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {
        //可忽略
    }

    @Override
    public void destroy() {
        //可忽略
    }
}
